package huawei.widget;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import o.fo;
import o.fpq;
import o.fpv;
import o.fqa.b;
import o.fqa.c;
import o.fqa.d;
import o.fqa.e;
import o.fqa.j;
import o.gg;

public class HwAlphaIndexerListView extends View {
    private String ʻ;
    private int ʻॱ;
    private int ʼ;
    private boolean ʼॱ;
    private List<String> ʽ;
    private boolean ʽॱ;
    private float ʾ;
    private boolean ʿ;
    private float ˈ;
    private boolean ˉ;
    Runnable ˊ;
    private boolean ˊˊ;
    private Context ˊˋ;
    private int ˊॱ;
    private boolean ˊᐝ;
    private String ˋ;
    private a ˋˊ;
    private Paint ˋˋ;
    private int ˋॱ;
    private Drawable ˋᐝ;
    private TextView ˌ;
    private PopupWindow ˍ;
    private String ˎ;
    private ListView ˎˎ;
    private String[] ˏ;
    private Handler ˏˏ;
    private int ˏॱ;
    private int ͺ;
    private String[] ॱ;
    private int ॱˊ;
    private int ॱˋ;
    private int ॱˎ;
    private List<String> ॱॱ;
    private int ॱᐝ;
    private int ᐝ;
    private int ᐝॱ;

    public interface a {
        void ˊ(String str, int i);
    }

    public HwAlphaIndexerListView(Context context) {
        this(context, null);
    }

    public HwAlphaIndexerListView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwAlphaIndexerListView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˊ = new Runnable(this) {
            final /* synthetic */ HwAlphaIndexerListView ˋ;

            {
                this.ˋ = r1;
            }

            public void run() {
                if (this.ˋ.ˍ != null) {
                    this.ˋ.ˍ.dismiss();
                }
            }
        };
        this.ˋ = "A";
        this.ˎ = "Z";
        this.ॱॱ = new ArrayList(10);
        this.ʽ = new ArrayList(10);
        this.ʼ = -1;
        this.ᐝ = -1;
        this.ʻॱ = -1;
        this.ʿ = false;
        this.ˊᐝ = false;
        this.ˉ = false;
        this.ˊˊ = true;
        this.ˋˋ = new Paint();
        this.ˏˏ = new Handler();
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, j.ʿ);
        this.ʻॱ = obtainStyledAttributes.getColor(j.ˉ, -16777216);
        this.ॱˎ = obtainStyledAttributes.getColor(j.ˊˋ, -7829368);
        this.ॱˋ = obtainStyledAttributes.getColor(j.ˋˊ, -16777216);
        this.ॱᐝ = obtainStyledAttributes.getColor(j.ˊˊ, -16776961);
        obtainStyledAttributes.recycle();
        ˏ(context);
    }

    private void ˏ(Context context) {
        boolean z = true;
        this.ˊˋ = context;
        Resources resources = this.ˊˋ.getResources();
        this.ˋᐝ = fo.ˊ(this.ˊˋ, c.ˏ);
        if (this.ˋᐝ != null) {
            gg.ॱ(gg.ʻ(this.ˋᐝ), this.ॱˎ);
        }
        if (VERSION.SDK_INT >= 24) {
            this.ʼॱ = fpq.ˎ().ॱ(this.ˋ) != 1;
        } else {
            this.ʼॱ = false;
        }
        if (resources.getConfiguration().orientation != 2) {
            z = false;
        }
        this.ʿ = z;
        this.ˋॱ = resources.getDimensionPixelSize(o.fqa.a.ˊ);
        this.ˏॱ = resources.getDimensionPixelSize(o.fqa.a.ˎ);
        this.ᐝॱ = resources.getDimensionPixelSize(o.fqa.a.ʽ);
        this.ʾ = (float) resources.getDimensionPixelSize(o.fqa.a.ʼ);
    }

    public void ॱ(boolean z, boolean z2) {
        Object obj = (String[]) fpv.ॱ().ˎ().toArray(new String[0]);
        Object obj2 = (String[]) fpv.ॱ().ॱॱ().toArray(new String[0]);
        int ॱ = ॱ();
        if (this.ʼॱ) {
            ॱ(z, z2, ॱ, obj, obj2);
        } else {
            if (ॱ == 26) {
                if (!z) {
                    obj2 = obj;
                }
            } else if (ॱ != 18) {
                fpv.ॱ();
                obj2 = (String[]) ˎ(fpv.ॱ(ॱ, Arrays.asList(obj))).toArray(new String[0]);
            }
            this.ˏ = new String[(obj2.length + 1)];
            if (z2) {
                this.ˏ[this.ˏ.length - 1] = "#";
                System.arraycopy(obj2, 0, this.ˏ, 0, obj2.length);
            } else {
                this.ˏ[0] = "#";
                System.arraycopy(obj2, 0, this.ˏ, 1, obj2.length);
            }
        }
        if (!this.ʼॱ || this.ʽॱ) {
            this.ʽ = new ArrayList(Arrays.asList(this.ˏ));
        } else {
            this.ʽ = new ArrayList(Arrays.asList(this.ॱ));
        }
        this.ʿ = z;
        invalidate();
    }

    private void ॱ(boolean z, boolean z2, int i, String[] strArr, String[] strArr2) {
        Object obj = (String[]) fpv.ˊ().toArray(new String[0]);
        Object obj2 = (String[]) fpv.ˋ().toArray(new String[0]);
        if (i == 26) {
            if (!z) {
                obj = obj2;
                strArr2 = strArr;
            }
        } else if (i != 18) {
            fpv.ॱ();
            List ॱ = fpv.ॱ(i, Arrays.asList(strArr));
            fpv.ॱ();
            strArr2 = (String[]) ˎ(ॱ).toArray(new String[0]);
            obj = (String[]) ˎ(fpv.ॱ(i, Arrays.asList(obj2))).toArray(new String[0]);
        }
        this.ˏ = new String[(strArr2.length + 2)];
        this.ॱ = new String[(obj.length + 2)];
        if (z2) {
            this.ˏ[this.ˏ.length - 1] = "#";
            this.ॱ[this.ॱ.length - 1] = "#";
            System.arraycopy(strArr2, 0, this.ˏ, 0, strArr2.length);
            this.ʼ = 0;
            this.ॱ[0] = this.ˏ[this.ʼ];
            System.arraycopy(obj, 0, this.ॱ, 1, obj.length);
            this.ˏ[this.ˏ.length - 2] = this.ॱ[this.ॱ.length - 2];
            return;
        }
        this.ˏ[0] = "#";
        this.ॱ[0] = "#";
        System.arraycopy(strArr2, 0, this.ˏ, 1, strArr2.length);
        this.ʼ = 1;
        this.ॱ[1] = this.ˏ[this.ʼ];
        System.arraycopy(obj, 0, this.ॱ, 2, obj.length);
        this.ˏ[this.ˏ.length - 1] = this.ॱ[this.ॱ.length - 1];
    }

    private int ॱ() {
        int paddingBottom = (int) (((float) ((((this.ˊॱ - this.ˏॱ) - this.ˏॱ) - getPaddingBottom()) - getPaddingTop())) / this.ʾ);
        if (paddingBottom > 26) {
            return 26;
        }
        if (paddingBottom <= 26 && paddingBottom > 12) {
            return 18;
        }
        if (paddingBottom <= 12 && paddingBottom > 10) {
            return 14;
        }
        if (paddingBottom > 10 || paddingBottom <= 8) {
            return 6;
        }
        return 10;
    }

    private List<String> ˎ(List<String> list) {
        List<String> arrayList = new ArrayList(10);
        for (String str : list) {
            if (str.split(HwAccountConstants.BLANK).length > 1) {
                arrayList.add("•");
            } else {
                arrayList.add(str);
            }
        }
        return arrayList;
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        this.ˊॱ = getMeasuredHeight();
        ॱ(this.ʿ, this.ˉ);
    }

    public void setListViewAttachTo(ListView listView) {
        this.ˎˎ = listView;
        if (!this.ˊᐝ) {
            ListAdapter adapter = this.ˎˎ.getAdapter();
            if (adapter instanceof HwSortedTextListAdapter) {
                this.ˉ = ((HwSortedTextListAdapter) adapter).isDigitLast();
            }
            ॱ(this.ʿ, this.ˉ);
            this.ˊᐝ = true;
        }
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        ʼ();
        int right = getRight();
        int left = getLeft();
        int i = right - left;
        if (i > this.ᐝॱ) {
            right -= (i - this.ᐝॱ) / 2;
            left += (i - this.ᐝॱ) / 2;
        }
        setRight(right);
        setLeft(left);
        int size = this.ʽ.size();
        right = this.ᐝ == -1 ? ʽ() : this.ᐝ;
        int width = getWidth();
        for (i = 0; i < size; i++) {
            this.ˋˋ.setColor(this.ॱˋ);
            this.ˋˋ.setAntiAlias(true);
            this.ˋˋ.setTextSize(this.ʾ);
            this.ˋˋ.setTypeface(Typeface.create(getResources().getString(d.ˏ), 0));
            if (i == right) {
                this.ˋˋ.setColor(this.ॱᐝ);
                this.ˋˋ.setTypeface(Typeface.create(getResources().getString(d.ˊ), 0));
            }
            String replace = ((String) this.ʽ.get(i)).replace("劃", "");
            canvas.drawText(replace, (((float) width) / 2.0f) - (this.ˋˋ.measureText(replace) / 2.0f), this.ͺ == this.ˏॱ ? ((((float) (i + 1)) * (this.ʾ + this.ˈ)) + ((float) this.ͺ)) - this.ˈ : (((float) (i + 1)) * (this.ʾ + this.ˈ)) + ((float) this.ͺ), this.ˋˋ);
            this.ˋˋ.reset();
        }
    }

    public void setShowPopup(boolean z) {
        this.ˊˊ = z;
    }

    private int ʽ() {
        if (this.ʻ != null) {
            int size = this.ʽ.size();
            for (int i = 0; i < size; i++) {
                if (ˏ((String) this.ʽ.get(i), this.ʻ, i)) {
                    return i;
                }
            }
        }
        return -1;
    }

    private void ʼ() {
        int size = this.ʽ.size();
        float f = this.ʾ;
        if (size < 6 && this.ˋॱ > 0) {
            this.ˏॱ = ((6 - size) * 4) * this.ˋॱ;
        }
        if (this.ˎˎ != null) {
            this.ॱˊ = this.ˎˎ.getHeight() - this.ˊॱ;
            int i = this.ˏॱ;
            this.ˈ = ((((float) ((this.ˎˎ.getHeight() - i) - this.ॱˊ)) - (f * ((float) size))) - ((float) i)) / ((float) (size - 1));
            if (((float) i) > this.ˈ) {
                i = (int) (((float) i) - this.ˈ);
            }
            this.ͺ = i;
        }
    }

    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        if (motionEvent == null) {
            return false;
        }
        int action = motionEvent.getAction();
        float y = motionEvent.getY();
        boolean z;
        if (y < ((float) this.ͺ) || y > ((float) (getHeight() - this.ͺ))) {
            z = true;
        } else {
            z = false;
        }
        if ((action == 0 || action == 2) && r2) {
            return true;
        }
        int height = (int) (((y - ((float) this.ͺ)) / ((float) (getHeight() - (this.ͺ * 2)))) * ((float) this.ʽ.size()));
        switch (action) {
            case 0:
                if (height >= 0 && height < this.ʽ.size()) {
                    ˊ(height);
                    invalidate();
                    break;
                }
            case 1:
                ˋ();
                this.ᐝ = -1;
                invalidate();
                break;
            case 2:
                ˏ(motionEvent, height);
                break;
            case 3:
                ˋ();
                return false;
        }
        return true;
    }

    private void ˏ(MotionEvent motionEvent, int i) {
        if (i >= 0 && i < this.ʽ.size()) {
            ˊ(i);
            invalidate();
        }
    }

    private void ˊ(int i) {
        if (this.ˋˊ != null && this.ʽ != null && i >= 0 && i < this.ʽ.size()) {
            this.ˋˊ.ˊ((String) this.ʽ.get(i), i);
        }
    }

    private void ˋ(boolean z) {
        List arrayList;
        Animation loadAnimation;
        this.ʽ.clear();
        if (z) {
            arrayList = new ArrayList(Arrays.asList(this.ॱ));
        } else {
            arrayList = new ArrayList(Arrays.asList(this.ˏ));
        }
        this.ʽ = arrayList;
        this.ʽॱ = !z;
        if (z) {
            loadAnimation = AnimationUtils.loadAnimation(this.ˊˋ, e.ˏ);
        } else {
            loadAnimation = AnimationUtils.loadAnimation(this.ˊˋ, e.ॱ);
        }
        setAnimation(loadAnimation);
        ʼ();
        startAnimation(loadAnimation);
    }

    public Object[] ˎ() {
        if (this.ˎˎ != null) {
            ListAdapter adapter = this.ˎˎ.getAdapter();
            if (adapter instanceof HwSortedTextListAdapter) {
                return ((HwSortedTextListAdapter) adapter).getSections();
            }
        }
        return new String[0];
    }

    private boolean ᐝ() {
        if (this.ʻ == null) {
            return false;
        }
        Object[] ˎ = ˎ();
        String str = this.ʻ;
        if (ˎ != null && "#".equals(str)) {
            if (this.ˉ) {
                return false;
            }
            if (1 < ˎ.length) {
                str = (String) ˎ[1];
            }
        }
        return Collator.getInstance().compare(str, this.ˋ) < 0;
    }

    private void ॱॱ() {
        if (!this.ʼॱ) {
            return;
        }
        if (ᐝ()) {
            if (!this.ʽॱ) {
                ˋ(false);
            }
        } else if (this.ʽॱ) {
            ˋ(true);
        }
    }

    public boolean ˎ(int i) {
        if (!this.ʼॱ) {
            return false;
        }
        if (i == this.ʼ && !this.ʽॱ) {
            return true;
        }
        if (i == (this.ˉ ? this.ʽ.size() - 2 : this.ʽ.size() - 1) && this.ʽॱ) {
            return true;
        }
        return false;
    }

    public void ˎ(String str) {
        if (this.ˊˊ) {
            int i;
            this.ˏˏ.removeCallbacks(this.ˊ);
            int dimensionPixelSize = getResources().getDimensionPixelSize(o.fqa.a.ॱ);
            if (this.ˍ == null) {
                this.ˌ = new TextView(getContext());
                this.ˌ.setTextSize(0, (float) getResources().getDimensionPixelSize(o.fqa.a.ˏ));
                if (this.ˋᐝ != null) {
                    this.ˌ.setBackground(this.ˋᐝ);
                }
                this.ˌ.setTextColor(this.ʻॱ);
                this.ˌ.setTypeface(Typeface.DEFAULT_BOLD);
                this.ˌ.setGravity(17);
                this.ˍ = new PopupWindow(this.ˌ, dimensionPixelSize, dimensionPixelSize);
                this.ˍ.setAnimationStyle(b.ˋ);
            }
            int i2 = (this.ᐝ != -1 || str == null) ? 0 : 1;
            if (this.ᐝ == -1 || this.ᐝ >= this.ʽ.size() || !ˏ((String) this.ʽ.get(this.ᐝ), str, this.ᐝ)) {
                i = 0;
            } else {
                i = 1;
            }
            if (i2 != 0 || r0 != 0) {
                this.ˌ.setText(str);
                i = getResources().getDimensionPixelSize(o.fqa.a.ˋ);
                int[] iArr = new int[2];
                getLocationInWindow(iArr);
                int i3 = iArr[0];
                i2 = iArr[0] + this.ᐝॱ;
                if (getParent().getLayoutDirection() == 1) {
                    i += i2;
                } else {
                    i = (i3 - i) - dimensionPixelSize;
                }
                this.ˍ.showAtLocation(getRootView(), 8388627, i, 0);
            }
        }
    }

    public void ˊ() {
        ˎ(this.ʻ);
    }

    public void ˋ() {
        if (this.ˊˊ) {
            this.ˏˏ.postDelayed(this.ˊ, 800);
        }
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.ˍ != null) {
            this.ˍ.dismiss();
        }
    }

    public boolean ˏ() {
        return this.ʽॱ;
    }

    public void setPopupWindowBgDrawable(Drawable drawable) {
        this.ˋᐝ = drawable;
    }

    public void setInactiveAlphaColor(int i) {
        this.ॱˋ = i;
    }

    public void setSelectedAlphaColor(int i) {
        this.ॱᐝ = i;
    }

    public void setPopupTextColor(int i) {
        this.ʻॱ = i;
    }

    public void setOnItemClickListener(a aVar) {
        this.ˋˊ = aVar;
    }

    public void setOverLayInfo(String str) {
        if ("".equals(str)) {
            this.ʻ = "@";
            return;
        }
        this.ʻ = str;
        ॱॱ();
    }

    public void setOverLayInfo(int i, String str) {
        this.ᐝ = i;
        setOverLayInfo(str);
    }

    public boolean ˏ(String str, String str2) {
        if (str.length() != str2.length()) {
            return false;
        }
        Collator instance = Collator.getInstance();
        instance.setStrength(0);
        return instance.equals(str, str2);
    }

    public boolean ˏ(String str, String str2, int i) {
        Object obj = (str == null || str2 == null) ? 1 : null;
        Object obj2;
        if (i < 0 || i >= this.ʽ.size()) {
            obj2 = 1;
        } else {
            obj2 = null;
        }
        if (obj != null || r0 != null) {
            return false;
        }
        if (!str.equals("•")) {
            return ˏ(str, str2);
        }
        this.ॱॱ.clear();
        if (!this.ˉ) {
            this.ॱॱ.add("#");
        }
        int ॱ = ॱ();
        obj = fpv.ॱ().ʼ();
        fpv.ॱ();
        List ˋ = fpv.ˋ();
        Collection ᐝ = fpv.ॱ().ᐝ();
        if (this.ʼॱ) {
            ˎ(ॱ, obj, ˋ, ᐝ);
        } else if (ॱ == 26) {
            if (this.ʿ) {
                this.ॱॱ.addAll(ᐝ);
            } else {
                this.ॱॱ.addAll(obj);
            }
        } else if (ॱ == 18) {
            this.ॱॱ.addAll(ᐝ);
        } else {
            ˋ = this.ॱॱ;
            fpv.ॱ();
            ˋ.addAll(fpv.ॱ(ॱ, obj));
        }
        if (this.ˉ) {
            this.ॱॱ.add("#");
        }
        for (String ˏ : ((String) this.ॱॱ.get(i)).split(HwAccountConstants.BLANK)) {
            if (ˏ(ˏ, str2)) {
                return true;
            }
        }
        return false;
    }

    private void ˎ(int i, List<String> list, List<String> list2, List<String> list3) {
        if (this.ʽॱ) {
            if (i == 26) {
                if (this.ʿ) {
                    this.ॱॱ.addAll(list3);
                } else {
                    this.ॱॱ.addAll(list);
                }
            } else if (i == 18) {
                this.ॱॱ.addAll(list3);
            } else {
                List list4 = this.ॱॱ;
                fpv.ॱ();
                list4.addAll(fpv.ॱ(i, list));
            }
            this.ॱॱ.add(this.ˎ);
            return;
        }
        this.ॱॱ.add(this.ˏ[this.ʼ]);
        if (i == 26) {
            if (this.ʿ) {
                this.ॱॱ.addAll(fpv.ˏ());
            } else {
                this.ॱॱ.addAll(list2);
            }
        } else if (i == 18) {
            this.ॱॱ.addAll(fpv.ˏ());
        } else {
            list4 = this.ॱॱ;
            fpv.ॱ();
            list4.addAll(fpv.ॱ(i, list2));
        }
    }
}
